var _timer = 30000;
var _split = 1;
var _id = 0;
var _status = "资料读取中...";

var g_numcolor = [0,1,1,2,2,3,3,1,1,2,2,3,1,1,2,2,3,3,1,1,2,3,3,1,1,2,2,3,3,1,1,2,3,3,1,1,2,2,3,3,1,2,2,3,3,1,1,2,2,3];
var colors = ["","red", "blue", "green"];
var XH = null;
var XH1= null;
if (window.XMLHttpRequest)
{// code for all new browsers
    XH = new XMLHttpRequest();
    XH1 = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{// code for IE5 and IE6
  XH = new ActiveXObject("Microsoft.XMLHTTP");
  XH1 = new ActiveXObject("Microsoft.XMLHTTP");
} else 
  alert("Your browser does not support XMLHTTP.");

var mchk_15 = [[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0]];
var mchk_16 = [[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0]];
var mchk_17 = [[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]];
var mchk_23 = [[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0]];

var timer_id;
var chkbutmod = false;
var b153_num = "";
//   Math.round(n) = 去小数取整数，Math.floor(n) = 四舍五入到整数

function getcontent()
{
    XH.open("POST", "op.php?op=xml&fp=bnow22&id="+_id+"&split="+_split,false); 
    try{XH.send("");return XH.responseText; }catch(E){}
}

function timer()
{
	window.status = _status;
	var i, j;
	var str = getcontent();
	if (str=="") { alert("Error 1"); }
	if (str=="-1") { location.reload(); }

	var a = str.split("\n");
	j = 0;
	for (i=1; i<7; i++) {
		show_rate15(i, a[j++]);
		show_rate16(i, a[j++]);
		show_rate17(i, a[j++]);
		show_rate23(i, a[j++]);
	}
	show_titleAmu(a[j++]);
	window.status = "";

	// timer_id = setTimeout("timer()", _timer);
}

function show_rate23(j, str)
{
	var i,ii,k;
	var count0 = 0;
	var amount0 = 0;
	var a0 = str.split(",");
	var win = a0[0];
	for (i=1; i<3; i++) {
		bt = 23;
		ii = i+7;
		k = bt+"_"+j+"_"+ii;
		a00 = a0[i].split("@");
		rate = a00[0];
		count = a00[1]-0;
		amount = a00[2]-0;
		nms = j+" "+ii;
		mchk_23[j][i] = Math.floor(amount);
		document.all["rate_"+k].innerHTML = rate;
		if (count > 0) {
			document.all["amount_"+k].innerHTML = "<a href=op.php?op=agent&fp=betlist&dt1="+_open+"&dt2="+_open+"&bettype="+bt+"&numbers="+escape(nms)+">"+Math.floor(amount)+"</a>";
			document.all["chg_"+k].innerHTML = "<input type=checkbox id=rrr_"+k+" onclick=\"quickrrr('"+k+"')\">";
		} else {
			document.all["amount_"+k].innerHTML = Math.floor(amount);
			document.all["chg_"+k].innerHTML = "<input disabled type=checkbox id=rrr_"+k+">";
		}
		win1 = Math.floor(win - a00[3]);
		document.all["win_"+k].innerHTML = win1;
		document.all["win_"+k].className = (win1 < 0 ? "lost" : "win");
		count0+=count;
		amount0+=amount;
	}
}

function show_rate17(j, str)
{
	var i,ii,k;
	var count0 = 0;
	var amount0 = 0;
	var a0 = str.split(",");
	var win = a0[0];
	for (i=1; i<4; i++) {
		bt = 17;
		ii = i+4;
		k = bt+"_"+j+"_"+ii;
		a00 = a0[i].split("@");
		rate = a00[0];
		count = a00[1]-0;
		amount = a00[2]-0;
		nms = j+" "+ii;
		mchk_17[j][i] = Math.floor(amount);
		document.all["rate_"+k].innerHTML = rate;
		if (count > 0) {
			document.all["amount_"+k].innerHTML = "<a href=op.php?op=agent&fp=betlist&dt1="+_open+"&dt2="+_open+"&bettype="+bt+"&numbers="+escape(nms)+">"+Math.floor(amount)+"</a>";
			document.all["chg_"+k].innerHTML = "<input type=checkbox id=rrr_"+k+" onclick=\"quickrrr('"+k+"')\">";
		} else {
			document.all["amount_"+k].innerHTML = Math.floor(amount);
			document.all["chg_"+k].innerHTML = "<input disabled type=checkbox id=rrr_"+k+">";
		}
		win1 = Math.floor(win - a00[3]);
		document.all["win_"+k].innerHTML = win1;
		document.all["win_"+k].className = (win1 < 0 ? "lost" : "win");
		count0+=count;
		amount0+=amount;
	}
}

function show_rate16(j, str)
{
	var i,ii,k;
	var count0 = 0;
	var amount0 = 0;
	var a0 = str.split(",");
	var win = a0[0];
	for (i=1; i<3; i++) {
		bt = 16;
		ii = i+2;
		k = bt+"_"+j+"_"+ii;
		a00 = a0[i].split("@");
		rate = a00[0];
		count = a00[1]-0;
		amount = a00[2]-0;
		nms = j+" "+ii;
		mchk_16[j][i] = Math.floor(amount);
		document.all["rate_"+k].innerHTML = rate;
		if (count > 0) {
			document.all["amount_"+k].innerHTML = "<a href=op.php?op=agent&fp=betlist&dt1="+_open+"&dt2="+_open+"&bettype="+bt+"&numbers="+escape(nms)+">"+Math.floor(amount)+"</a>";
			document.all["chg_"+k].innerHTML = "<input type=checkbox id=rrr_"+k+" onclick=\"quickrrr('"+k+"')\">";
		} else {
			document.all["amount_"+k].innerHTML = Math.floor(amount);
			document.all["chg_"+k].innerHTML = "<input disabled type=checkbox id=rrr_"+k+">";
		}
		win1 = Math.floor(win - a00[3]);
		document.all["win_"+k].innerHTML = win1;
		document.all["win_"+k].className = (win1 < 0 ? "lost" : "win");
		count0+=count;
		amount0+=amount;
	}
}

function show_rate15(j, str)
{
	var ii,k;
	var count0 = 0;
	var amount0 = 0;
	var a0 = str.split(",");
	var win = a0[0];
	for (ii=1; ii<3; ii++) {
		bt = 15;
		k = bt+"_"+j+"_"+ii;
		a00 = a0[ii].split("@");
		rate = a00[0];
		count = a00[1]-0;
		amount = a00[2]-0;
		nms = j+" "+ii;
		mchk_15[j][ii] = Math.floor(amount);
		document.all["rate_"+k].innerHTML = rate;
		if (count > 0) {
			document.all["amount_"+k].innerHTML = "<a href=op.php?op=agent&fp=betlist&dt1="+_open+"&dt2="+_open+"&bettype="+bt+"&numbers="+escape(nms)+">"+Math.floor(amount)+"</a>";
			document.all["chg_"+k].innerHTML = "<input type=checkbox id=rrr_"+k+" onclick=\"quickrrr('"+k+"')\">";
		} else {
			document.all["amount_"+k].innerHTML = Math.floor(amount);
			document.all["chg_"+k].innerHTML = "<input disabled type=checkbox id=rrr_"+k+">";
		}
		win1 = Math.floor(win - a00[3]);
		document.all["win_"+k].innerHTML = win1;
		document.all["win_"+k].className = (win1 < 0 ? "lost" : "win");
		count0+=count;
		amount0+=amount;
	}
}
function show_titleAmu(str)
{
	var a0 = str.split(",");
	var i = 0;
	var l = a0.length;
	var amu = 0;
	var clr = '';
	var oObj = '';
	for (i=0; i<l; i++) {
		a00 = a0[i].split("@");
		amu = a00[0];
		if(a00[1] > 0){ clr = '#ffff99';  }else{ clr = 'transparent';  }
    oObj = document.getElementById("menuAmu"+i);
    oObj.innerHTML = amu;
    oObj.style.backgroundColor = clr;
	}
}
function quickrrr(k)
{
	if (document.all["rrr_"+k].checked) {
		if (!chkbutmod) {
			chkbutmod = true;
		}
		if (timer_id) clearTimeout(timer_id);
		// timer_id = setTimeout("timer()", 60000);
	}
}

function gen_rate15()
{
	ret = "<table width=100% cellpadding=2 cellspacing=1 border=0 class=table0>"
		+"<tr id=rate0hd class=td0 align=center><td rowspan=2></td>"
		+"<td colspan=4>"+_name3[1]+"</td><td colspan=4>"+_name3[2]+"</td>"
		+"<td colspan=4>"+_name3[3]+"</td><td colspan=4>"+_name3[4]+"</td></tr><tr class=td0 align=center>";
	
	for (i=0; i<4; i++) ret += _tb15head;
	ret += "</tr>";
	
	for (j=1; j<7; j++) {
		ret += "<tr class=td2 align=right><td class=td15 nowrap align=center>"+_name4+_name5[j]+"</td>";
		for (i=1; i<5; i++) {
			k = (i < 3 ? 15 : 16)+"_"+j+"_"+i;
			ret += "<td nowrap id=amount_"+k+"></td><td nowrap id=win_"+k+"></td><td id=rate_"+k+" class=rate></td><td align=center id=chg_"+k+"></td>";
		}
	}
	ret += "</table>";
	document.all.div15.innerHTML = ret;
}

function gen_rate17()
{
	ret = "<table width=100% cellpadding=2 cellspacing=1 border=0 class=table0>"
		+"<tr id=rate0hd class=td0 align=center><td rowspan=2></td>"
		+"<td colspan=4>"+_name3[5]+"</td><td colspan=4>"+_name3[6]+"</td>"
		+"<td colspan=4>"+_name3[7]+"</td>"
		+"<td colspan=4>"+_name3[8]+"</td><td colspan=4>"+_name3[9]+"</td></tr><tr class=td0 align=center>";
	
	for (i=0; i<5; i++) ret += _tb15head;
	ret += "</tr>";
	
	for (j=1; j<7; j++) {
		ret += "<tr class=td2 align=right><td class=td15 nowrap align=center>"+_name4+_name5[j]+"</td>";
		for (i=5; i<10; i++) {
			k = (i<8 ? 17 : 23)+"_"+j+"_"+i;
			ret += "<td nowrap id=amount_"+k+"></td><td nowrap id=win_"+k+"></td><td id=rate_"+k+" class=rate></td><td align=center id=chg_"+k+"></td>";
		}
	}
	ret += "</table>";
	document.all.div17.innerHTML = ret;
}

function protect_b1()
{
	var bw = 282;
	var sr = 0;
	var hi =104;
	var bt = 0;
	var ii = 0;
	var kk = "";
	var count = 0;
	var _bet = new Array();
	var _num = new Array();
	var _ord = new Array();
	var _chk = new Array();
	var _rate = new Array();
	var _amount = new Array();
	b153_num = document.all.b153.value-0;
	if (b153_num > 0) {
		for (j=1; j<7; j++) {
			for (i=1; i<3; i++) {
				bt = 23;
				ii = i+7;
				kk = bt+"_"+j+"_"+ii;
				if (document.all["rrr_"+kk].checked) {
					_bet[count] = bt;
					_ord[count] = j;
					_num[count] = ii;
					_rate[count] = document.all["rate_"+kk].innerHTML;
					_chk[count] = mchk_23[j][i];
					_amount[count] = b153_num;
					count++;
				}
			}
		}
		for (j=1; j<7; j++) {
			for (i=1; i<4; i++) {
				bt = 17;
				ii = i+4;
				kk = bt+"_"+j+"_"+ii;
				if (document.all["rrr_"+kk].checked) {
					_bet[count] = bt;
					_ord[count] = j;
					_num[count] = ii;
					_rate[count] = document.all["rate_"+kk].innerHTML;
					_chk[count] = mchk_17[j][i];
					_amount[count] = b153_num;
					count++;
				}
			}
		}
		for (j=1; j<7; j++) {
			for (i=1; i<3; i++) {
				bt = 16;
				ii = i+2;
				kk = bt+"_"+j+"_"+ii;
				if (document.all["rrr_"+kk].checked) {
					_bet[count] = bt;
					_ord[count] = j;
					_num[count] = ii;
					_rate[count] = document.all["rate_"+kk].innerHTML;
					_chk[count] = mchk_16[j][i];
					_amount[count] = b153_num;
					count++;
				}
			}
		}
		for (j=1; j<7; j++) {
			for (ii=1; ii<3; ii++) {
				bt = 15;
				kk = bt+"_"+j+"_"+ii;
				if (document.all["rrr_"+kk].checked) {
					_bet[count] = bt;
					_ord[count] = j;
					_num[count] = ii;
					_rate[count] = document.all["rate_"+kk].innerHTML;
					_chk[count] = mchk_15[j][ii];
					_amount[count] = b153_num;
					count++;
				}
			}
		}
		if (count > 0) {
			hi += (count * 26);
			if (count > 24) {
				sr = 1;
				bw = 300;
				hi = 794;
			}
			var X = screen.width - bw - 10;
			var Y = 0;
			//alert(" _bet: "+_bet+"\n _ord: "+_ord+"\n _num: "+_num+"\n _chk: "+_chk);
			// var newwin = window.open("op.php?op=agent&fp=protsaves2&btype="+_bet+"&ord="+_ord+"&num="+_num+"&rate="+_rate+"&amount="+_amount+"&chk="+_chk,'WinProtPop','menubar=no,status=yes,scrollbars='+sr+',toolbar=no,top='+Y+',left='+X+',width='+bw+',height='+hi);
			var newwin = myCreateDiv("op.php?op=agent&fp=protsaves2&btype="+_bet+"&ord="+_ord+"&num="+_num+"&rate="+_rate+"&amount="+_amount+"&chk="+_chk);
      //setTimeout("isPopOpen(newwin)",1500);
		}
	}
	b153_num = "";
	document.all.b153.value = b153_num;
	if (chkbutmod) {
		chkbutmod = false;
		timer();
	}
}

function prot_list()
{
	var X = (screen.width-470)/2;
	var Y = (screen.Height-424)/2;
	// var newwin = window.open("op.php?op=agent&fp=protlists&bmd=8",'WinPopList','menubar=no,status=yes,scrollbars=no,toolbar=no,top='+Y+',left='+X+',width=540,height=412');
	var newwin = myCreateDiv("op.php?op=agent&fp=protlists&bmd=8");
  //setTimeout("isPopOpen(newwin)",1500);
}

function w(s) {
	document.write(s);
}

function myCreateDiv(sSrc){
    var shadow = document.createElement("div");
    shadow.setAttribute("id","speShadow2");
    shadow.style.zIndex="100";

    var box = document.createElement("div");
    box.setAttribute("id","speBox2");
    box.style.zIndex="999";
    
    var closeBar = document.createElement("div");
    closeBar.setAttribute("id","closeBar");
    
    var iptClose = document.createElement("input");
    iptClose.setAttribute("type","button");
    iptClose.setAttribute("value"," X ");
    iptClose.setAttribute("className","c4");
    iptClose.onclick = function() {myCloseMyDiv(0);};
    
    closeBar.appendChild(iptClose);
    box.appendChild(closeBar);
    
    var myIframe = document.createElement("iframe");
    myIframe.setAttribute("id","myIfram_target");
    myIframe.setAttribute("name","myIfram_target");
    myIframe.style.width = "100%";
    myIframe.style.height = "100%";
    myIframe.src = sSrc;
    box.appendChild(myIframe);
    
    document.body.appendChild(shadow);
    document.body.appendChild(box);    
}

function myCloseMyDiv(oReload){
    var shadow=document.getElementById("speShadow2");
    if(shadow != undefined){
      var box=document.getElementById("speBox2");
      document.body.removeChild(box);
      document.body.removeChild(shadow);
      if(oReload) window.location.reload();
    }
    
}

function winonload()
{
	gen_rate15();
	gen_rate17();

	b153_num = document.all.b153.value-0;
	chkbutmod = false;
	timer();
}

window.onload = winonload;